<?php
	include_once("dbi.php");

	$user_logged = isset($_SESSION[''.SECURITY_SESSION.'']['username']) ? $_SESSION[''.SECURITY_SESSION.'']['username'] : FALSE;

	echo "<div id='text'><a class='title'>My Reservations » ".$user_logged."</a></div>";
	
	if ($user_logged){
		$now_date = date("Y-m-d H:i:s", mktime(date("H"), date("i")+5, 0, date("m"), date("d"), date("Y")));
		
		//Display My Nodes/Channels
		$error = 0;
		$connection = array('HOST' => ''.HOST_MYSQL.'', 'USER' => ''.USER_MYSQL.'', 'PASS' => ''.PASS_MYSQL.'', 'INVENTORY_DB' => ''.DB_INVENTORY.'', 'SCHEDULER_DB' => ''.DB_SCHEDULER.'');

		$cancel_n = $_REQUEST['cancel_n'];
		$c_reserve_id = $_REQUEST['reservation_id'];
		if($cancel_n) { cancelReservation_Id($c_reserve_id, $connection); }

		$cancel_c = $_REQUEST['cancel_c'];
		$c_spec_id = $_REQUEST['spec_reserve_id'];
		if($cancel_c) { cancelSpecReservation_Id($c_spec_id, $connection); }
	
		$my_nodes = getMyNodes($user_logged, $connection);
		$my_channels = getMyChannels($user_logged, $connection);
		
		$numOfNodes = count($my_nodes);
		$numOfChannels = count($my_channels);
		
		echo "<div class='institution_title2'>My Reservations from ".ISLAND_NAME."</div>";
		
		echo "<table id='reserve' class='table_max'>
				<tr class='top'>
					<td>Node</td>
					<td>Begin Time</td>
					<td>End Time</td>
					<td>Actions</td>
				</tr>";
				
		if($numOfNodes == 0){
			echo "<tr><td colspan='4'>You Have not a Node Reservation</td></tr>";
		}
		
		for($i = 0; $i < $numOfNodes; $i++){
			$node_description = "<center><b>Node description:</b></center>" .
								"<b>Hostname:</b> ".$my_nodes[$i]['node_name']."<br>" .
								"<b>Control IP:</b> ".$my_nodes[$i]['control_ip']."";
			
			echo "<tr>
				<td><span onMouseOver=\"toolTip('".$node_description."', 200)\" onMouseOut=\"toolTip()\">Node ".$my_nodes[$i]['node_id']."</span></td>
				<td>".$my_nodes[$i]['begin_time']."</td>
				<td>".$my_nodes[$i]['end_time']."</td>
				<td>
					<form method='POST' action=''>
						<input type='hidden' name='reservation_id' value='".$my_nodes[$i]['reservation_id']."'>
						<input type='submit' name='cancel_n' value='Cancel'>
					</form>
				</td>
			</tr>";
		}
		
		echo "</table>";
		
		echo "<table id='reserve' class='table_max'>
				<tr class='top'>
					<td>Channel</td>
					<td>Begin Time</td>
					<td>End Time</td>
					<td>Actions</td>
				</tr>";
				
		if($numOfChannels == 0){
			echo "<tr><td colspan='4'>You Have not a Channel Reservation</td></tr>";
		}
		
		for($i = 0; $i < $numOfChannels; $i++){
				echo "<tr>
					<td>Channel ".$my_channels[$i]['channel']."</td>
					<td>".$my_channels[$i]['begin_time']."</td>
					<td>".$my_channels[$i]['end_time']."</td>
					<td>
						<form method='POST' action=''>
							<input type='hidden' name='spec_reserve_id' value='".$my_channels[$i]['id']."'>
							<input type='submit' name='cancel_c' value='Cancel'>
						</form>
					</td>
				</tr>";
		}
		
		echo "</table>";
	}else{
		set_message('You do not have a slice! Please contact LABORA for a slice creation!','error',1);
	}
?>		
